<template>
	<el-dialog title="工作计划反馈" v-model="visible" :width="500" destroy-on-close @closed="$emit('closed')">
		<el-form :model="form" :rules="rules" :disabled="mode=='show'" ref="dialogForm" label-width="100px" label-position="left">
			<el-form-item label="反馈意见" prop="remark">
				<el-input v-model="form.remark" maxlength="150" clearable type="textarea" placeholder="反馈意见"></el-input>
			</el-form-item>
			<el-form-item label="相关文件" prop="attachId">
				<sc-upload-file :apiObj="apiObj" v-model="fileList" :data="{module:'workplan'}" :showFileList="false" @success="addNewFile">
					<el-button type="primary" icon="el-icon-upload">上传附件</el-button>
				</sc-upload-file>
				<attach-menu v-model:attachIds="form.attachId" :roleFlag="4" :preview="true"></attach-menu>
			</el-form-item>
		</el-form>
		<template #footer>
			<el-button @click="visible=false" >取 消</el-button>
			<el-button v-if="mode!='show'" type="primary" :loading="isSaveing" @click="submit()">确 定</el-button>
		</template>
	</el-dialog>
</template>

<script>
	import AttachMenu from "@/views/module/attachMenu";

	export default {
		components: {
			AttachMenu
		},
		emits: ['success', 'closed'],
		data() {
			return {
				mode: "add",
				titleMap: {
					add: '新增',
					edit: '编辑',
					show: '查看'
				},
				apiObj:this.$API.file.attach.uploadFile,
				visible: false,
				isSaveing: false,
				fileList:[],
				//表单数据
				form: {
					planId:'',
					attachId:"",
					remark: ""
				},
				//验证规则
				rules: {
					remark: [
						{required: true, message: '反馈意见不能为空'}
					],
				}
			}
		},
		mounted() {
		},
		methods: {
			//显示
			open(){
				this.visible = true;
				return this
			},
			//表单提交方法
			submit(){
					this.$refs.dialogForm.validate(async (valid) => {
						if (valid) {
							this.isSaveing = true;
							var res = await this.$API.office.workPlan.insertWorkPlanProcess.post(this.form);
							this.isSaveing = false;
							if(res.code == 200){
								this.$emit('success')
								this.visible = false;
								this.$message.success("操作成功")
							}else{
								this.$alert(res.message, "提示", {type: 'error'})
							}
						}
					})
			},
			addNewFile(res, file)
			{
				let tArr = this.form.attachId.split(",");
				tArr.push(res.data.attachId);
				this.form.attachId = tArr.join(",");
			},
			setData(data){
				this.form.planId = data.planId
			},
		}
	}
</script>

<style>
</style>
